import React, { Component } from 'react'
import {
    Modal,
} from 'react-bootstrap';

import FormInput from '../../../core/components/form.input';

class LevelEdit extends Component {

    static defaultProps = {
        levelData: {},
        isShow: false,
    };

    state = {
        levelData: this.props.levelData,
        isShow: this.props.isShow,
    };

    componentWillReceiveProps = (props) => {
        this.setState({ ...props });
    };

    render() {
        let { levelData } = this.state;
        return (
            <Modal show={this.state.isShow} keyboard={true}>
                <Modal.Header>
                    <Modal.Title>{this.props.id ? '更新分档' : '新增分档'}</Modal.Title>
                </Modal.Header>
                <Modal.Body>
                    <form>
                        <FormInput label="理财金额" name="targetNum" dataItem={levelData}></FormInput>
                        <FormInput label="预期收益" name="rate" dataItem={levelData}></FormInput>
                    </form>
                </Modal.Body>
                <Modal.Footer>
                    <button type="button" className="btn btn-default" onClick={this._close}>关闭</button>
                    <button type="button" className="btn btn-primary" onClick={this._save}>确定</button>
                </Modal.Footer>
            </Modal>
        )
    }

    _close = () => {
        this.setState({ isShow: false });
    };

    _save = () => {
        let { levelData } = this.state;
        if (levelData.targetNum && levelData.rate) {
            this.props.onEdit(this.state.levelData);
        }
    };
}

export default LevelEdit